﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XMLGener.Data
{
    public class XDepthCalculatingObject
    {
        XDepthCalculatingObject(XMLGenerRangeElement el)
        {

        }

        public int depth;
        public bool depthIsOk = false;
        public Stack<XMLGenerRangeElement> stack = new Stack<XMLGenerRangeElement>();
        public Stack<XMLGenerRangeElement> depthProblems = new Stack<XMLGenerRangeElement>();
        public Dictionary<string, XMLGenerElementType> recursions = new Dictionary<string, XMLGenerElementType>();


        public void checkDepth()
        {
            depthProblems= new Stack<XMLGenerRangeElement>();
            foreach (XMLGenerRangeElement el in stack)
            {
                if (el.minTotalElemens > 1)
                    depthProblems.Push(el);
            }
        }

        private void reset()
        {
            this.stack = new Stack<XMLGenerRangeElement>();
            this.depthProblems = new Stack<XMLGenerRangeElement>();
            this.depthIsOk = false;
        }

        public void loadFromDepth(XDepthCalculatingObject prevoiusDepth)
        {
            reset();
            if (prevoiusDepth == null)
                return;
            this.depth = prevoiusDepth.depth + 1;
            this.stack = new Stack<XMLGenerRangeElement>();
            XMLGenerElement elem  =null;
            foreach (XMLGenerRangeElement el in prevoiusDepth.stack )
            {
                if (el is XMLGenerElement)
                    elem = el as XMLGenerElement;
                if (elem!=null )
                {
                    if (elem.baseType != null)
                    {
                        this.recursions.Add(elem.parentTypeName, elem.baseType as XMLGenerElementType);
                        foreach (XMLGenerRangeElement childNode in elem.baseType.childNodes)
                            stack.Push(childNode);
                    }
                }

            }
        }



    }
}
